<?php

namespace app\shop\model\company;

use think\Model;
use app\shop\model\user\User;
use think\model\concern\SoftDelete;
/**
 * 应用模型
 */
class Examine extends Model
{
    use SoftDelete;
    protected $autoWriteTimestamp = true;

    const STATUS_ON = 0;    //进行中
    const STATUS_FINISH = 1;    //已完成
    const STATUS_TIMEOUT = 2;    //已超时

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'user_id');
    }

    public function hrUser()
    {
        return $this->belongsTo(User::class, 'hr', 'user_id');
    }

    public function managerUser()
    {
        return $this->belongsTo(User::class, 'manager', 'user_id');
    }

    public function department()
    {
        return $this->belongsTo(Department::class, 'department_id', 'id');
    }

    public function setStartTimeAttr($value)
    {
        return strtotime($value);
    }

    public function setEndTimeAttr($value)
    {
        return strtotime($value);
    }

    public function getStartTimeAttr($value)
    {
        return $value ? date('Y-m-d', $value) : "";
    }

    public function getEndTimeAttr($value)
    {
        return $value ? date('Y-m-d', $value) : "";
    }

    public function getStatusTextAttr($value, $data)
    {
        switch ($data['status']) {
            case self::STATUS_ON:
                return '进行中';
            case self::STATUS_FINISH:
                return '已完成';
            case self::STATUS_TIMEOUT:
                return '已超时';
            default:
                return '未知';
        }
    }

    public function getInterviewTimeAttr($value)
    {
        return $value ? date('Y-m-d H:i', $value) : "";
    }

    public function setInterviewTimeAttr($value)
    {
        return strtotime($value);
    }
}
